/**
 * 
 */
package org.cnbi.utils.pojo.industry;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.cnbi.entity.Company;
import org.cnbi.utils.exception.BusinessException;
import org.cnbi.utils.tools.GlobalConstants;
import org.codehaus.jackson.annotate.JsonIgnore;


/**
 * Copyright © 2014中国经邦. All rights reserved.
 * @author 龚佳新
 * @date 2014年5月28日上午11:24:19
 * @cnbi-utils
 * 
 * 行业参数查询Bean
 */
public class IndustryParamBean implements Serializable {
	
	
	@JsonIgnore
	private String company="1";
	
	private String sname="1";
	
	private String id;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@JsonIgnore
	private String code;//行业参数编码
	@JsonIgnore
	private String type="c";//公司行业类型
	@JsonIgnore
	private String range="1";//公司行业级别
	@JsonIgnore
	private String year = "2013";
	@JsonIgnore
	private String subject = "inds";
	
	private int indicator;
	
	
	@JsonIgnore
	private String cacheKey;
	
	
	
	private BigDecimal bad = new BigDecimal(-3.20);
	
	private BigDecimal lowers= new BigDecimal(0.20);
	
	private BigDecimal average= new BigDecimal(3.85);
	
	private BigDecimal good= new BigDecimal(9.15);
	
	private BigDecimal excellent= new BigDecimal(14.29);
	
	
	
	/**
	 * @return the cacheKey
	 */
	public String getCacheKey() {
		this.cacheKey = code+type+range+year+subject;
		return this.cacheKey;
	}

	/**
	 * @param cacheKey the cacheKey to set
	 */
	public void setCacheKey(String cacheKey) {
		this.cacheKey = cacheKey;
	}

	public IndustryParamBean(){}

	/**
	 * @param code
	 * @param type
	 * @param range
	 * @param year
	 * @param subject
	 */
	public IndustryParamBean(String type, String range, String year, String subject) {
		super();
		this.type = type;
		this.range = range;
		this.year = year;
		this.subject = subject;
	}

	/**
	 * @return the code
	 */
	public String getCode() {
		return code;
	}

	/**
	 * @param code the code to set
	 */
	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * @return the range
	 */
	public String getRange() {
		return range;
	}

	/**
	 * @param range the range to set
	 */
	public void setRange(String range){
		this.range = range;
	}

	/**
	 * @return the year
	 */
	public String getYear() {
		return year;
	}

	/**
	 * @param year the year to set
	 */
	public void setYear(String year) {
		this.year = year;
	}

	/**
	 * @return the subject
	 */
	public String getSubject() {
		return subject;
	}

	/**
	 * @param subject the subject to set
	 */
	public void setSubject(String subject) {
		this.subject = subject;
	}

	/**
	 * @return the company
	 */
	public String getCompany() {
		return company;
	}

	/**
	 * @param company the company to set
	 */
	public void setCompany(String company) {
		this.company = company;
	}
	
	
	/**
	 * @return the bad
	 */
	public BigDecimal getBad() {
		return bad;
	}

	/**
	 * @param bad the bad to set
	 */
	public void setBad(BigDecimal bad) {
		this.bad = bad;
	}

	/**
	 * @return the lowers
	 */
	public BigDecimal getLowers() {
		return lowers;
	}

	/**
	 * @param lowers the lowers to set
	 */
	public void setLowers(BigDecimal lowers) {
		this.lowers = lowers;
	}

	/**
	 * @return the average
	 */
	public BigDecimal getAverage() {
		return average;
	}

	/**
	 * @param average the average to set
	 */
	public void setAverage(BigDecimal average) {
		this.average = average;
	}

	/**
	 * @return the good
	 */
	public BigDecimal getGood() {
		return good;
	}

	/**
	 * @param good the good to set
	 */
	public void setGood(BigDecimal good) {
		this.good = good;
	}

	/**
	 * @return the excellent
	 */
	public BigDecimal getExcellent() {
		return excellent;
	}

	/**
	 * @param excellent the excellent to set
	 */
	public void setExcellent(BigDecimal excellent) {
		this.excellent = excellent;
	}
	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}
	
	

	/**
	 * @return the sname
	 */
	public String getSname() {
		return sname;
	}

	/**
	 * @param sname the sname to set
	 */
	public void setSname(String sname) {
		this.sname = sname;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * 
	 */
	public List<IndustryParamBean> getQueryIndustryParamBeanList(Company company) {
		setRange(company.getRanges());
		setType(company.getType());
		List<IndustryParamBean> list = new ArrayList<IndustryParamBean>();
		String [] codes = this.code.split("\\,");//25_yysl,36_uui;
	      for (String codeStr : codes) {
			  String [] arr = codeStr.split("\\_");
			  int len = arr.length;
			  if(len>0){
		    	  IndustryParamBean bean = new IndustryParamBean(type,range,year,subject);
		    	  list.add(bean);
		    	  if(len==1){//如果传的长度为1  eg:06
		    		  bean.setCode(arr[0]);
		    	  }else if(len >= 2){//如果传的长度为2  eg:yylr_25
		    		  bean.setCode(arr[1]);
		    		  bean.setId(arr[0]);
		    		  if(len == 3){
		    			  bean.setSname(arr[2]);
		    		  }
		    	  }
			  }else{
				  throw new BusinessException("传入了错误的行业查询参数【"+this.code+"---eg:yylr_25 or 25】");
			  }
		  }
      return list;
	}

	/* 
	 * @data 2014年5月30日  复写的方法
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "IndustryParamBean [company=" + company + ", sname=" + sname + ", id=" + id + ", code=" + code + ", type=" + type + ", range=" + range + ", year=" + year + "]";
	}
	
	
	

}
